class Solution {
public:
    int subarraySum(vector<int>& nums, int k) {
        map<int,int>hash;
        int sum=0;
        int ret=0;hash[0]=1;
        for(auto x:nums)
        {
            sum+=x;
            if(hash[sum-k])ret+=hash[sum-k];
            hash[sum]++;
        }
        return ret;
    }
};
